package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.Organization;
import com.smz.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrganizationController {


    @Autowired
    private OrganizationService organizationService;


    @GetMapping("/organizations/{current}/{size}")
    public ResponseEntity<IPage<Organization>> findByPage(@PathVariable("current")Integer current,
                                                          @PathVariable("size")Integer size){
        IPage<Organization> byPage = organizationService.findByPage(current, size);
        return ResponseEntity.ok(byPage);

    }

    @PostMapping("organizations")
    public ResponseEntity<String>addOrganization(@RequestBody Organization organization){
        organizationService.addOrganization(organization);
        return ResponseEntity.ok("ok");
    }

    @PutMapping("organizations")
    public ResponseEntity<String>modifyOrganization(@RequestBody Organization organization){
        organizationService.modifyOrganization(organization);
        return ResponseEntity.ok("ok");
    }
    @DeleteMapping("organizations/{id}")
    public ResponseEntity<String>deleteOrganization(@PathVariable("id")Integer id){
        organizationService.removeOrganization(id);
        return ResponseEntity.ok("ok");
    }


}
